package com.example.camera;

import android.annotation.SuppressLint;
import android.hardware.Camera;

@SuppressLint("NewApi")
public class OpenCameraInterface {
	private static final String TAG = OpenCameraInterface.class.getName();
	
	public OpenCameraInterface() {
		
	}

	public static Camera open() {
		
		int nums = Camera.getNumberOfCameras();
		int index = 0;
		
		while(index < nums) {
			Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
			Camera.getCameraInfo(index, cameraInfo);
			if(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
				break;
			}
			index++;
		}
		
		Camera camera = null;
		
		if(index < nums) {
			camera = Camera.open(index);
		} else {
			camera = Camera.open(0);
			
		}
		
		
		return camera;
	}

}
